#ifndef _MODULE_CV_H___
#define _MODULE_CV_H___
#ifdef __cplusplus
 extern "C" {
#endif
	 
#include "stdint.h"
#include "stm32f4xx_can.h"
#include "bsp_uart.h"	 
 
	 
#define FRAME_DATA_SUM  16
typedef struct
{
	unsigned char  SOF;
	unsigned char  MOD;
	unsigned short LEN;
	unsigned int   CRC32;
	unsigned char  DATA[FRAME_DATA_SUM];
}FRAME;

void UsasrFrameInit(void);
uint32_t CRC_STM32Hard(uint8_t* pBuffer, uint32_t BufferLength);
uint32_t CRC_STM32Check(uint8_t* pBuffer, uint32_t BufferLength , uint32_t CRC32Rec);
void UsasrFrameSend(FRAME * pBuffer);
void UsasrFrameSend6(FRAME * pBuffer);
unsigned char UsasrFrameRec(unsigned char * str);

typedef enum {GameInfoID = 0x0001, RealBloodChangedDataID = 0x0002,RealShootDataID = 0x0003} FrameID;
typedef __packed struct
{
	uint8_t SOF;
	uint16_t DataLength;
	uint8_t Seq;
	uint8_t CRC8; 
	uint16_t CmdID;
}FrameHeader;
typedef enum{
	BUFF_TYPE_NONE,
	BUFF_TYPE_ARMOR = 0x01,
	BUFF_TYPE_SUPPLY = 0x04,
	BUFF_TYPE_BULLFTS= 0x08, 
}eBuffType;
typedef __packed struct
{
	uint8_t flag;
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t compass;
}tLocData;

typedef __packed struct
{
float data1;
float data2; 
float data3;
} data;

typedef __packed struct
{
	uint32_t remainTime;
	uint16_t remainLifeValue;
	float realChassisOutV;
	float realChassisOutA;
	tLocData locData;
	float remainPower;
}tGameInfo;
typedef __packed struct
{
	uint8_t weakId:4;
	uint8_t way:4;
	uint16_t value;
}tRealBloodChangedData;
typedef __packed struct
{
	float realBulletShootSpeed;
	float realBulletShootFreq;
	float realGolfShootSpeed;
	float realGolfShootFreq;
}tRealShootData;


typedef __packed struct
{
	int8_t ID;
	int8_t Flag;
	short Distance;
	float Theta;
	//int16_t RES;
}CVStruct;

//typedef __packed struct//16Bytes
//{
//	int64_t CRC_Check;// 8Bytes
//	int8_t ID;//1Bytes
//	int8_t Flag;//1Bytes
//  short Distance;//2Bytes
//	float Theta;//4Bytes
//	//int16_t RES;
//}MyCVStruct;

#define ToCVStructPointer(_ptemp)  ((CVStruct*)_ptemp)
void CV_ToCar(CVStruct *pMsg);
void CV_FromCar(CanRxMsg *pMsg);
void CV_ToServer(float data1,float data2,float data3);
uint16_t Get_CRC16_Check_Sum(uint8_t *pchMessage,uint32_t dwLength,uint16_t wCRC);
unsigned char Get_CRC8_Check_Sum(unsigned char *pchMessage,unsigned int dwLength,unsigned char ucCRC8);
unsigned char crc8(char *buf);

#ifdef __cplusplus
 }
#endif
#endif
 